# Contributor: Tom Parker-Shemilt <palfrey@tevp.net>
# Maintainer: Sodface <sod@sodface.com>
pkgname=netpbm
pkgver=11.8.1
pkgrel=0
pkgdesc="Toolkit for manipulation of graphic images"
url="https://netpbm.sourceforge.net/"
arch="all"
license="IJG AND BSD-3-Clause AND GPL-2.0-only"
checkdepends="diffutils musl-locales"
makedepends="
	bash
	flex
	ghostscript
	libjpeg-turbo-dev
	libpng-dev
	libx11-dev
	libxml2-dev
	perl
	sed
	tiff-dev
	zlib-dev
	"
subpackages="$pkgname-static $pkgname-dev $pkgname-doc $pkgname-extras::noarch"
source="https://github.com/ceamac/netpbm-make-dist/releases/download/v$pkgver/netpbm-$pkgver.tar.xz
	config.mk
	manweb.conf
	01-makefile.patch
	02-installnetpbm.patch
	"

build() {
	cat config.mk.in "$srcdir"/config.mk > config.mk

	make
	make package pkgdir="$PWD/pkgdir"
}

check() {
	# disable failing tests
	sed -i -e '/^pbmtext-iso88591.test/d' \
		-e '/^ppmpat-random.test/d' \
		-e '/^ppmtomitsu.test/d' \
		-e '/^pnmindex.test/d' \
		"$builddir"/test/Test-Order

	# Some tests sporadically fail, try to repeat 3 times before failing.
	local i; for i in $(seq 0 3); do
		[ $i -eq 0 ] || msg "Retrying ($i/3)..."
		make check pkgdir="$PWD/pkgdir" && return 0
		sleep 1
	done
	return 1
}

package() {
	mkdir -p "$pkgdir"/usr/bin/ \
		"$pkgdir"/usr/include/netpbm \
		"$pkgdir"/usr/lib/pkgconfig

	BUILDDIR="$builddir" PKGDIR="$pkgdir" ./installnetpbm

	sed -i -e "s|$pkgdir||g" "$pkgdir"/usr/lib/pkgconfig/netpbm.pc

	install -Dm644 -t "$pkgdir"/etc "$srcdir"/manweb.conf

	install -Dm644 -t "$pkgdir"/usr/share/doc/$pkgname/html \
		"$builddir"/userguide/*.html

	install -Dm644 "$builddir"/doc/copyright_summary \
		"$pkgdir"/usr/share/licenses/$pkgname/COPYING
}

doc() {
	default_doc
	depends="perl lynx"

	amove etc/manweb.conf
	amove usr/bin/manweb
}

extras() {
	pkgdesc="$pkgdesc (perl scripts)"
	depends="perl"

	amove usr/bin/pamfixtrunc
	amove usr/bin/pbmtox10bm
	amove usr/bin/pgmcrater
	amove usr/bin/pnmflip
	amove usr/bin/pnmquant
	amove usr/bin/pnmquantall
	amove usr/bin/ppmfade
	amove usr/bin/ppmquant
	amove usr/bin/ppmquantall
	amove usr/bin/ppmrainbow
	amove usr/bin/ppmshadow
}

sha512sums="
e4b1e8d7468fcd0233e50861e890669c788f95924edb6b6256f93b53d2ab16b7fd2c2099ca238b409fba7c764e51d54a9fbdbb22bb3bb1acf8296afdb807bd4f  netpbm-11.8.1.tar.xz
7dc16e0ad3229fac35c3ddecdbfb43ebfb1a2b778e53ca34d5f45f738e15fd131298bc8faa6b9a428380ffa4f1c9b2101934b79fe37bb7e6c046910fcf8ac45c  config.mk
bfd56c3c071528e5a5eac9455bdb0f4fbe524159d28291f65c6d5cda6cb31ac96efffb3f671f308007d3af8e69480423a8eb92bc54d9545ced45b9980c108571  manweb.conf
098f4270b20b585559fcd6ba088c5294ebfac02e912ed1f86577550c2b45bc7c61a22e9be1177116bdb7b21e51f0758b5612cd6eef2b0f03e8de06a69e241529  01-makefile.patch
2bfa679d4c4d95ba43c17840ad0025d2560ed9ac8d47c248ba611325f93898ab05ea5709b4c5447e72dac66acdd41687c483de22bdb85fb2ee4669c7b9d30e88  02-installnetpbm.patch
"
